package com.jhws.business.local.api;

import com.jhws.business.card.bo.TblCardPerms;
import com.jhws.business.local.bo.LocalConstant;
import com.jhws.business.local.service.CardPermsSynchService;
import com.jhws.common.base.bo.JsonRespData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;

@Controller
@RequestMapping("/localSynch/cardPerms")
public class CardPermsSynchApi {
    @Resource
    private CardPermsSynchService cardPermsSynchService;

    @RequestMapping(value = "cardPerms")
    @ResponseBody
    public JsonRespData saveOwner(@RequestBody TblCardPerms cardPerms) throws Exception {
        if (cardPerms.getIsSynch() == LocalConstant.SYNCH_STATE_NO) {
            cardPermsSynchService.saveCardPerms(cardPerms);
        } else if ((cardPerms.getIsSynch() == LocalConstant.SYNCH_STATE_DEL)) {
            cardPermsSynchService.deleteCardPerms(cardPerms);
        }
        return new JsonRespData("", 1, "");
    }


    @RequestMapping(value = "anon/test")
    @ResponseBody
    public JsonRespData test() throws Exception {
        cardPermsSynchService.mergeCardPerms("http://test.jhws.top:8081/", "0008", new HashMap<String, String>() {
            {
                put("commCode", "0008");
                put("commPassword", "201688");
            }
        });
        return new JsonRespData("", 1, "");
    }
}
